home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / joy32 / vbjoy32.bas < prev    next >
BASIC Source File  |  1997-07-28  |  3KB  |  89 lines

  1. Attribute VB_Name = "Module1"
  2. Option Explicit
  3.  
  4. '-------------------------------------------------------
  5. ' JOYSTICK.BAS - Joystick support routines for
  6. '                Visual Basic 4.0.
  7. '-------------------------------------------------------
  8. ' Joystick Device ID
  9. Global Const JOYSTICK1 = 0
  10. Global Const JOYSTICK2 = 1
  11. ' Joystick error return values
  12. Global Const JOYERR_NOERROR = 0
  13. Global Const JOYERR_PARMS = 165
  14. Global Const MMSYSERR_NODRIVER = 6
  15. Global Const JOYERR_UNPLUGGED = 167
  16. ' Joystick button bit-flags used by tJoyInfo.ButtonStates
  17. Global Const JOY_BUTTON1 = &H1
  18. Global Const JOY_BUTTON2 = &H2
  19. Global Const JOY_BUTTON3 = &H4
  20. Global Const JOY_BUTTON4 = &H8
  21. ' Joystick Position
  22. Type tJoyInfo
  23.     X As Long
  24.     Y As Long
  25.     Z As Long
  26.     ButtonStates As Long
  27.     ' This is determined by the fields above.
  28.     ButtonDown(1 To 4) As Integer
  29. End Type
  30. ' Joystick Capabilities
  31. Const MAXPNAMELEN = 32
  32. Const MAXOEMVXD = 128
  33. Type tJoyCaps
  34.     Mid As Integer
  35.     Pid As Integer
  36.     Pname As String * MAXPNAMELEN
  37.     Xmin As Long
  38.     Xmax As Long
  39.     Ymin As Long
  40.     Ymax As Long
  41.     Zmin As Long
  42.     Zmax As Long
  43.     NumButtons As Long
  44.     PeriodMin As Long
  45.     PeriodMax As Long
  46.     wRmin As Long
  47.     wRmax As Long
  48.     wUmin As Long
  49.     wUmax As Long
  50.     wVmin As Long
  51.     wVmax As Long
  52.     wCaps As Long
  53.     wMaxAxes As Long
  54.     wNumAxes As Long
  55.     wMaxButtons As Long
  56.     szRegKey As String * MAXPNAMELEN
  57.     szOEMVxD As String * MAXOEMVXD
  58. End Type
  59. Global JoyCaps As tJoyCaps
  60. ' Joystick API Calls
  61. Declare Function joyGetDevCaps Lib "winmm.dll" Alias "joyGetDevCapsA" (ByVal IDDevice As Integer, JCaps As tJoyCaps, ByVal CapSize As Integer) As Integer
  62. Declare Function joyGetPos Lib "winmm.dll" (ByVal IDDevice As Integer, JPos As tJoyInfo) As Integer
  63. Function GetJoystickPos(IDDevice As Long, JoyInfo As tJoyInfo) As Integer
  64. '-------------------------------------------------------
  65. ' This function is a wrapper around the joyGetPos API
  66. ' call.  That call returns coordinates as unsigned
  67. ' long integers, which VB doesn't support.  We move
  68. ' these coordinates into long values so that they
  69. ' can be easily evaluated.
  70. '-------------------------------------------------------
  71. Dim rc As Integer
  72. Static NotFirstTime As Integer
  73.     If Not NotFirstTime Then
  74.         NotFirstTime = False
  75.         rc = joyGetDevCaps(IDDevice, JoyCaps, Len(JoyCaps))
  76.         If rc <> 0 Then
  77.             GetJoystickPos = rc
  78.             Exit Function
  79.         End If
  80.     End If
  81.     rc = joyGetPos(IDDevice, JoyInfo)
  82.     GetJoystickPos = rc
  83.     If rc <> 0 Then Exit Function
  84.     JoyInfo.ButtonDown(1) = (JoyInfo.ButtonStates And JOY_BUTTON1) = JOY_BUTTON1
  85.     JoyInfo.ButtonDown(2) = (JoyInfo.ButtonStates And JOY_BUTTON2) = JOY_BUTTON2
  86.     JoyInfo.ButtonDown(3) = (JoyInfo.ButtonStates And JOY_BUTTON3) = JOY_BUTTON3
  87.     JoyInfo.ButtonDown(4) = (JoyInfo.ButtonStates And JOY_BUTTON4) = JOY_BUTTON4
  88. End Function
  89.